package com.yanqu.road.server.cmd.cookboy.cross;

import com.yanqu.road.entity.activity.cookboy.CookBoyData;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.CookBoyPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_COOK_BOY_SERVE_RESP, desc = "跨服返回食材参赛结果")
public class CrossServeFoodRespCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		CookBoyProto.CrossCookBoyServeRespMsg crossRespMsg = CookBoyProto.CrossCookBoyServeRespMsg.parseFrom(packet.getBytes());
		GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
		ret = crossRespMsg.getRet();
		CookBoyProto.CookBoyServeFoodRespMsg.Builder respMsg = CookBoyProto.CookBoyServeFoodRespMsg.newBuilder();
		if(ret == 0){
			CookBoyProto.CookBoyFinishFoodTempMsg tempFoodMsg = crossRespMsg.getFinishFood();
			CookBoyData cookBoyData = CookBoyMgr.serveFoodRespond(crossRespMsg.getActivityId(),packet.getPlayerId(),crossRespMsg.getNo(),tempFoodMsg.getId());
			CookBoyProto.CookBoySelfTableSyncMsg.Builder selfTableMsg = CookBoyPb.parseSelfTableSync(cookBoyData);
			CookBoyProto.CookBoyPublicTableSyncMsg.Builder publicTableMsg = CookBoyProto.CookBoyPublicTableSyncMsg.newBuilder(crossRespMsg.getPublicTable());
//			CookBoyMgr.syncScenePublicTable(crossRespMsg.getActivityId(),publicTableMsg);
			respMsg.setPublicTable(publicTableMsg);
			respMsg.setSelfTable(selfTableMsg);
		}
		respMsg.setRet(ret);
		gamePlayer.sendPacket(Protocol.U_COOK_BOY_SERVE_FOOD, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
